//
//  FindAnchorCell.swift
//  FM
//
//  Created by x on 2017/9/22.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class FindAnchorCell: UICollectionViewCell {
    
    /// cell显示的数据模型
    var model:Radio? {
        didSet {
            iconImage.sd_setImage(with: model?.user?.avaterURL)
            nameLable.text = model?.user?.nickname
            likeLable.text = "喜欢:" + (model?.favnum)!
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    /// 初始化
    func setupUI() -> Void {
        
        //1.添加子控件
        contentView.addSubview(iconImage)
        contentView.addSubview(nameLable)
        contentView.addSubview(likeLable)
        
        //2.布局子控件
        var cons:[NSLayoutConstraint] = [NSLayoutConstraint]()
        
        let dict = ["iconImage":iconImage,"nameLable":nameLable,"likeLable":likeLable] as [String : Any] 
        
        cons += NSLayoutConstraint.constraints(withVisualFormat: "H:|-20-[iconImage(50)]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: nil, views: dict)
        cons += NSLayoutConstraint.constraints(withVisualFormat: "V:|-10-[iconImage(50)]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: nil, views: dict)
        
        cons += NSLayoutConstraint.constraints(withVisualFormat: "H:[iconImage]-4-[nameLable]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: nil, views: dict)
        cons += NSLayoutConstraint.constraints(withVisualFormat: "V:|-20-[nameLable]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: nil, views: dict)
        
        cons += NSLayoutConstraint.constraints(withVisualFormat: "H:[iconImage]-4-[likeLable]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: nil, views: dict)
        cons += NSLayoutConstraint.constraints(withVisualFormat: "V:[nameLable]-4-[likeLable]", options: NSLayoutFormatOptions.init(rawValue: 0), metrics: nil, views: dict)

        
        contentView.addConstraints(cons)
        
    }
    
    //MARK: -- 懒加载
    
    private lazy var iconImage:UIImageView = UIImageView.imageWith(radios: 25, imageName: "")
        
    private lazy var nameLable:UILabel = UILabel.lableWith(title: "", titleColor: UIColor.black, fontSize: 10)
    
    private lazy var likeLable:UILabel = UILabel.lableWith(title: "", titleColor: UIColor(white: 0.7, alpha: 0.7), fontSize: 10)
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
}
